package com.weetop.aklyscan.activity.sreach;

import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.base.BaseActivity;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.SerailBean;
import com.weetop.aklyscan.presenter.SearchPresent;
import com.weetop.aklyscan.utils.BaseUtils;
import com.weetop.aklyscan.view.SearchView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SearchDetailsActivity extends BaseActivity<SearchPresent> implements SearchView {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private ArrayList<SerailBean.DataBean> data = new ArrayList<>();
    private CommonRecyclerAdapter<SerailBean.DataBean> adapter;
    private String keywords;

    @Override
    protected SearchPresent createPresenter() {
        return new SearchPresent(this, this);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_details);
        ButterKnife.bind(this);
        keywords = getIntent().getStringExtra("id");

        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<SerailBean.DataBean>(mActivity, R.layout.item_search_detail, data) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, SerailBean.DataBean item, int position) {
                helper.setText(R.id.tv_xuhao, position + 1 + "");
                helper.setText(R.id.sn, item.getSerial_code());
                helper.setText(R.id.model, item.getGoods_model());
                helper.setText(R.id.name, item.getGoods_name());
                helper.setText(R.id.zzx_code, item.getTransit_code());
            }
        };
        recyclerView.setAdapter(adapter);
        mPresenter.serail1(keywords);
    }

    @Override
    public void getserailSuccess(BaseModel<SerailBean> o) {
        SerailBean serailBean = o.getData();
        data.clear();
        adapter.clear();
        data.addAll(serailBean.getList());
        adapter.addAll(serailBean.getList());
    }

    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                if (BaseUtils.fastClick()) {
                    finish();
                }
                break;
        }
    }
}
